<?php
class Default_Form_Product extends Zend_Form
{
    public function init()
    {
        $this->setName("default");                        
        
        $id = new Zend_Form_Element_Hidden('id');
        $id->addFilter('Int');
        
        $title = new Zend_Form_Element_Text('title');
        $title->setLabel('Tiêu đề (*)')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty',false,array('messages'=>'Thiếu tiêu đề tin đăng'));
        $title->setAttrib('class','form-control')->setAttrib('style','width:95%')->setAttrib('maxlength','50');
                
        $startD = new Zend_Form_Element_Text('startDate');
        $startD->setLabel('Ngày Bắt Đầu (*)')->addFilter('StripTags')->addFilter('StringTrim');
        $startD->setAttrib('class','form-control datepicker2')->setAttrib('placeholder','yyyy-mm-dd')->setAttrib('style','width:90%');
        //$startD->setAttrib('readonly','');
        $endD = new Zend_Form_Element_Text('endDate');
        $endD->setLabel('Ngày Kết Thúc (*)')->addFilter('StripTags')->addFilter('StringTrim');
        $endD->setAttrib('size', 60)->setAttrib('class','form-control datepicker2')->setAttrib('placeholder','yyyy-mm-dd')->setAttrib('style','width:90%');
        //$endD->setAttrib('readonly','');                                        

        $con = new Zend_Form_Element_Textarea('content');
        $con->setLabel('Nội dung (*)')->setRequired(true)->addValidator('NotEmpty',false,array('messages'=>'Vui lòng thêm mô tả cho sản phẩm'));
        $con->setAttrib('rows', 10)->setAttrib('style','width:85%');
        
        $price = new Zend_Form_Element_Text('price');
        $price->setLabel('Giá sản phẩm - VNĐ')->addFilter('StripTags')->addFilter('StringTrim')->addValidator('Digits',false,array('messages'=>'Giá tiền không hợp lệ'));
        $price->setAttrib('class','form-control')->setAttrib('style','width:95%');                       
                        
        $human = new Zend_Form_Element_Select('human');
        $human->setLabel('Bạn là');                        
        $configCar= new Zend_Config_Ini(CONFIG_PATH.'/human.ini', APPLICATION_ENV);
        $huL=$configCar->human->toArray();        
        foreach($huL as $k => $v){
            $human->addMultiOption($k,$v);    
        }
        $human->setAttrib('class','form-control')->setAttrib('style','width:90%');
         
        $tran = new Zend_Form_Element_Select('transaction');
        $tran->setLabel('Bạn cần');                        
        $configTran= new Zend_Config_Ini(CONFIG_PATH.'/transaction.ini', APPLICATION_ENV);
        $tranL=$configTran->transaction->toArray();        
        foreach($tranL as $k => $v){
            $tran->addMultiOption($k,$v);    
        }       
        $tran->setAttrib('class','form-control')->setAttrib('style','width:90%');                                  
        
        $item = new Zend_Form_Element_Select('itemId');
        $item->setLabel('Thuộc danh mục sản phẩm');          
        $modeC = new Admin_Model_Productcat();
        $modelI = new Admin_Model_Productitem();        
        $catL = $modeC->getAllData();        
        foreach($catL as $o){
            $item->addMultiOption('cat-'.$o->id,'--- '.$o->name.' ---');
            $arrT[] = 'cat-'.$o->id;                         
            $itemL = $modelI->getDataByCat($o->id);            
            foreach($itemL as $t){
                $item->addMultiOption($t->id,$t->name);                  
            }      
        } 
        $item->setAttrib('disable',$arrT)->setAttrib('style','width:90%');
        $item->setAttrib('class','form-control');
        
        $area = new Zend_Form_Element_Select('areaId');
        $area->setLabel('Khu vực');        
        $modelA = new Admin_Model_Area();
        $areaL = $modelA->getAllData();        
        foreach($areaL as $o) $area->addMultiOption($o['id'],$o['name']);
        $area->setAttrib('class','form-control')->setAttrib('style','width:90%');
        
        $pho =new Zend_Form_Element_File('photo');                                                                  
        $pho->addValidator('Extension',true,array('jpg','gif','png'),'picture');                 
        $pho->addValidator('Size',true,array('min'=>'0KB','max'=>'300KB'),'picture');
        $pho->setMultiFile(7);        
        $pho->removeDecorator('dtddwrapper')->removeDecorator('HtmlTag')->removeDecorator('Label');  
                        
        // submit button
        $submit = new Zend_Form_Element_Button('submit');
        $submit->setAttrib('type','submit');
        $submit->setLabel('Đăng tin');
        $submit->setAttrib('id','submitbutton');
        $submit->setAttrib('class',"form-control")->setAttrib('style','width:150px;background-color:ForestGreen');
        $submit->removeDecorator('HtmlTag')->removeDecorator('DtDdWrapper');
                                
        
        $contact = new Zend_Form_Element_Text('contact');
        $contact->setLabel('Người liên hệ (*)')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty',false,array('messages'=>'Thiếu danh tính người bán'));
        $contact->setAttrib('class','form-control')->setAttrib('style','width:70%');        
        
        $mobile = new Zend_Form_Element_Text('mobile');
        $mobile->setLabel('Di động (*)')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')
            ->addValidator('NotEmpty',false,array('messages'=>'Thiếu số điện thoại người bán'))->addValidator('Digits',false,array('messages'=>'Số điện thoại không hợp lệ'))->addValidator('stringLength', false, array(8, 11,'messages'=>'Số điện thoại chưa chính xác'));
        $mobile->setAttrib('class','form-control')->setAttrib('style','width:70%');            
        
        $emailCont = new Zend_Form_Element_Text('emailCont');
        $emailCont->setLabel('Email')->addFilter('StripTags')->addFilter('StringTrim')->addValidator('EmailAddress');
        $emailCont->setAttrib('class','form-control')->setAttrib('style','width:70%');                
                
        $addressCont = new Zend_Form_Element_Text('addressCont');
        $addressCont->setLabel('Địa chỉ')->addFilter('StripTags')->addFilter('StringTrim');
        $addressCont->setAttrib('class','form-control')->setAttrib('style','width:70%');
        
        $priceAd = new Zend_Form_Element_Text('priceAd');
        $priceAd->setLabel('Phí đăng tin')->addFilter('StripTags')->addFilter('StringTrim')->setAttrib('readonly','true');
        $priceAd->setAttrib('class','form-control')->setAttrib('style','width:90%');          
                
        $this->setDecorators(array(
                               array('viewScript',
                               array('viewScript'=>'template/form_product.phtml'),
                        )));                
                
        // add elements to form
        $this->addElements(array (
            $id, $human, $tran, $area, $item, $title, $startD, $endD, $priceAd, $con, $price, $pho, $contact, $mobile, $emailCont, $addressCont,          
            $submit
        ));   
                                     
    }
}

